import org.chenmin.system.*;

 
class BootStrap {

    def init = { servletContext ->
		
		if(User.count()==0){
			def adminRole = new Role(authority: 'ROLE_ADMIN').save(flush: true)
					def userRole = new Role(authority: 'ROLE_USER').save(flush: true)
					
					def testUser = new User(username: 'me', password: 'password')
			testUser.save(flush: true)
			
			def test2User = new User(username: 'user', password: 'password')
			test2User.save(flush: true)
			
			UserRole.create testUser, adminRole, true
			UserRole.create test2User, userRole, true
			
			assert User.count() == 2
			assert Role.count() == 2
			assert UserRole.count() == 2
		}
    }
    def destroy = {
    }
}
